The PrinterClassDriver folder contains sample code for a USB printer driver. It consists of a unit table driver, a USB printer class driver, and a Chooser package. Please note that this sample provides the basic communications infrastructure to transfer data to and from a USB printer. It does not contain any of the rasterizing or other code needed to fully support the Mac OS Printing Manager.
Description
The PrinterClassDriver sample demonstrates the use of the Mac OS USB to create a driver for a printer class device. This sample includes a unit table driver which routes I/O requests between the Mac OS Printing Manager and the class driver. It also includes a Chooser package which enumerates the available printers of a given model. The Chooser uses this package to allow the user to select which printer to use.
Building the Code
This sample was built using the Metrowerks CodeWarrior Pro 4, IDE version 3.2 environment and Mac OS USB DDK version 1.4.1f4. Also required are Universal Interfaces and Libraries 3.3. Later versions of these tools can also be used: consult the Mac OS USB DDK Readme file to determine which version of Universal Interfaces and Libraries to use. This driver is designed to be compatible with Mac OS USB releases back to version 1.0.1.
This sample class driver is based on the actual printer class driver that Apple ships with Mac OS 9.0 and later. As such, it will load for any generic printer class device that does not have a vendor specific driver installed. If you do supply your own printer driver, it absolutely must be vendor specific and not generic. This way the driver is not matched as a generic driver for a device that it may not actually support. It must be named differently from the Apple USB printer driver, and match to your vendor ID and product ID.
To accomplish this, modify the vendor ID, product ID, and driver loading options fields of the class driver’s USBDriverDescription structure located in the source file PrintDriverShell.c. Set the vendor and product IDs to the appropriate values for your device, and set the driver loading options to kUSBDoNotMatchGenericDevice. If your device is a composite class device with a printer class interface, also set the kUSBInterfaceMatchOnly bit in the driver loading options field.
To rebuild the project, place the PrinterClassDriver folder into the USBDDK:Examples: folder. The CodeWarrior project file assumes certain project-specific access paths. The resulting class driver, USBPrintDriver, along with the associated Chooser extension, USB Driver Sample, are built into the USBDDK:Extensions-MCWBuilt: folder.
Changes from the previous release of the PrinterClassDriver sample:
1. The project now uses the correct DrvrGlue.a.o object file. In previous releases, the DrvrGlue.a file had been updated correctly, however, the DrvrGlue.a.o file was still built from an older version of the source.
2. The printer driver checks which version of USB is present and calls USBExpertStatus instead of USBExpertStatusLevel when running with releases of USB prior to USB 1.2.
Converting the CodeWarrior project file:
The supplied Metrowerks CodeWarrior (CW) Project file was created using CW Pro 4, IDE 3.2. If you use a different version of CW Pro, you will have to convert the project file. If you have problems with the resulting driver, check the following project preference settings:
1. PrinterClassDRVR target - 68K Processor panel - ensure that the 4-Byte Ints option is checked.
2. PrinterClassDriver target - PPC Processor panel - ensure that the Struct Alignment is set to 68K.
Bug Reports:
If you find any bugs, please send them to "usb@isg.apple.com" and include "Attn: Garth Cummings" and I will try to address them.
Questions:
For any questions which you may have with this sample or with Mac OS USB, please submit them to either the Mac OS USB Developer mailing list, usb@isg.apple.com, or to Apple Worldwide Developer Technical Support (WWDTS), dts@apple.com. If you are not familiar with the WWDTS support plans, please check them out at the Developer Programs web page,
<http://developer.apple.com/programs/>.
To subscribe to the Mac OS USB Developer mailing list, send an email to usb@isg.apple.com with the subject set to "subscribe".